<template>
  <!-- 自定义表单验证：自己写if之类的规则（能写出所有的表单验证）
    表单元素值绑定
    el-form
        model
        rules:{
          prop的值:[
          {required:true...},
          {min:.......},
          {pattern:.......},
          {validator:(rule,value,callback)=>{
            rule:当前已有规则，基本不用
            value:当前需要验证的值
            callback:
              成功:callback()
              失败:callback(new Error('错误信息'))
          }}
          ]
        }
    el-form-item
        prop

  -->
  <div>
    <el-form :model="form" :rules="rules">
      <el-form-item label="密码" prop="password">
        <el-input v-model="form.password" />
      </el-form-item>
      <el-form-item label="确认密码" prop="repassword">
        <el-input v-model="form.repassword" />
      </el-form-item>
    </el-form>

  </div>
</template>
<script>
export default {
  data() {
    return {
      form: {
        password: '',
        repassword: ''
      },
      rules: {
        password: [{ required: true, message: '必填', trigger: 'change' }, {
          validator: (rule, value, callback) => {
            const reg = /^1[3-9]\d{9}$/
            if (reg.test(value)) {
              callback()
            } else {
              callback(new Error('错误的密码：不是正确手机号'))
            }
          }
        }],
        repassword: [{ required: true, message: '必填', trigger: 'change' },
          { validator: (rule, value, callback) => {
            if (value === this.form.password) { callback() } else {
              callback(new Error('确认密码与密码不一致'))
            }
          } }
        ]

      }
    }
  }
}
</script>
<style>
</style>
